<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="org.tigr.htc.persist.*" %>
<%@ page import="org.tigr.htc.common.*" %>
<%@ page import="org.tigr.htc.cmd.*" %>

<%
   IPersist pl = PersistFactory.getIPersist();
   String[] colors = new String[] { "#ececec", "#dc9000" };
%>
<html>
<head>
</head>

<body>
<%
  String where = "";
  String order = "";
  String isSubmit = request.getParameter("sub_form");

  if(isSubmit != null && isSubmit.equals("t")) {
    where = request.getParameter("sub_where");
    order = request.getParameter("sub_order");
  }

%>
<H1> HTCRequest Status Page </H1>
<table border=1>
<form method="post" action="cmd_status.jsp">
<input type="hidden" name="sub_form" value="t" />
<tr>
<td> where </td>
<td><input type="text" name="sub_where" value="<%= where %>" length="40" /></td>
</tr>
<tr>
<td> order by </td>
<td><input type="text" name="sub_order" value="<%= order %>" length="40" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="search" /></td>
</tr>

</form>
</table>
<br>
<table border=1>
<form method="post" action="cmd_status.jsp">
<tr bgcolor="#00a8ec">
<td>--</td>
<td>ID</td>
<td>Group</td>
<td>Username</td>
<td>Command</td>
<td>Command Name</td>
<td>State</td>
<td>Status W/R/C/E</td>
<td>Submitted</td>
<td>Started</td>
</tr>

<%
  List list = pl.searchCommands(where, order, null);
  Iterator iter = list.iterator();
  Command cmd;    
  CommandStatus cstatus;


  for (int i = 0; iter.hasNext(); i++) {
      String stat = "Not Available";

      cmd = (Command) iter.next();
      cstatus = cmd.getStatus();
      if(cstatus != null) {
      stat = cstatus.getWaiting() + "/" + cstatus.getRunning() + "/" +
	cstatus.getCompleted() + "/" + cstatus.getErrors();
      }
%>

<tr bgcolor="<%= colors[(i % 2)] %>">
<td><input type="checkbox" name="checked" value="<%= cmd.getID() %>" ></td>
<td><%= cmd.getID() %></td>
<td><%= cmd.getState() %></td>
<td><%= cmd.getGroup() %></td>
<td><%= cmd.getUserName() %></td>
<td><%= cmd.getCommand() %></td>
<td><%= cmd.getName() %></td>
<td><%= stat %>
<td><%= cmd.getSubmitTime() %></td>
<td><%= cmd.getStartTime() %></td>
</tr>
<% } %>
<tr bgcolor="#00a8ec">
<td colspan="9"> stop all selected </td>
</tr>
</form>
</table>

</body>
</html>
